scikit-learn: MultiLabelBinarizer
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MultiLabelBinarizer.html
Transform between iterable of iterables and a multilabel format.
💡イテラブルのイテラブルを渡す
下の例はset(イテラブル)のlist(イテラブル)
transformしたラベルはmulti-hot encodingというらしい(要確認)
inverse_transformメソッドで0と1の並びを渡してラベルに戻せる
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MultiLabelBinarizer.html#sklearn.preprocessing.MultiLabelBinarizer.inverse_transform
Transform the given indicator matrix into label sets.
各サンプルにつきクラス数だけの0/1を並べる
code:inverse_transform.py
>> from sklearn.preprocessing import MultiLabelBinarizer
>> mlb = MultiLabelBinarizer()
>> mlb.fit_transform({'sci-fi', 'thriller'}, {'comedy'})
array([0, 1, 1,
1, 0, 0])
>> import numpy as np
>> mlb.inverse_transform(np.array(0,1,1],[1,0,0)) # ラベルのクラス名に戻せる!
('sci-fi', 'thriller'), ('comedy',)
classes_属性
A copy of the classes parameter when provided. Otherwise it corresponds to the sorted set of classes found when fitting.
ソート済み=fitしたときにsortしている(classesが与えられなかった場合)
https://github.com/scikit-learn/scikit-learn/blob/1.1.3/sklearn/preprocessing/_label.py#L758